import { Body, Query, Controller, Get, HttpCode, Post } from '@nestjs/common';
import { FoodService } from './food.service';
import { ApiOperation, ApiTags } from '@nestjs/swagger';
import type {
  QueryParam,
  AddParam,
  UpdateParam,
  DeleteParam,
} from './food.interface';

@ApiTags('食品管理')
@Controller('food')
export class FoodController {
  constructor(private readonly foodService: FoodService) {}

  // 查询全部数据
  @Get('query')
  @HttpCode(200)
  @ApiOperation({ summary: '查询全部数据' })
  findAll(@Query('keyword') keyword: QueryParam['keyword']) {
    return this.foodService.findAll(keyword);
  }

  //  新增
  @Post('add')
  @HttpCode(200)
  @ApiOperation({ summary: '新增' })
  addFood(@Body() food: AddParam) {
    return this.foodService.addFood(food);
  }

  // 更新
  @Post('update')
  @HttpCode(200)
  @ApiOperation({ summary: '更新' })
  updateFood(@Body() food: UpdateParam) {
    return this.foodService.updateFood(food);
  }

  @Get('delete')
  @HttpCode(200)
  @ApiOperation({ summary: '删除' })
  deleteFood(@Query('id') id: DeleteParam['id']) {
    return this.foodService.deleteFood(id);
  }
}
